import { _decorator, Color, Component, Sprite } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Collider')
export class Collider extends Component {
    private sprite: Sprite = null;
    private isHit: boolean = false;

    protected onLoad(): void {
        this.sprite = this.node.getComponent(Sprite);
    }

    setColor(color: Color) {
        if (this.sprite)
            this.sprite.color = color;
    }

    onTrigger(): void {
        this.isHit = true;
    }

    protected update(dt: number): void {
        this.setColor(this.isHit ? Color.GREEN : Color.WHITE);
        this.isHit = false;
    }
}

